function concaturl(url) {
  return `${window.RPConfig.mgt}/post/${url}`;
}

// getRolePostId
export const getRolePostId = id => $http.post(concaturl("getRoleByPostId?postId=" + id));

// get user post
export const getUserPost = id => $http.post(concaturl(`getPostByUserId?userId=${id}`));

// 保存用户 post
export const saveUserAssignedPost = param => $http.post(concaturl("addUserPostRel"), param);

// AddPost
export const addPost = param => $http.post(concaturl("add"), param);

// get detail
export const getPostDetail = id => $http.post(concaturl(`getById?postId=${id}`));

// update
export const updatePost = param => $http.post(concaturl("updateById"), param);

// get post all user
export const getPostAllUser = param => $http.post(concaturl(`getUserListPage?appId=${param.condition.appId}`), param);

// get post user
export const getPostAssignedUser = id => $http.post(concaturl(`getUserByPostId?postId=${id}`));

// SavePostAssignedUser
export const savePostAssignedUser = param => $http.post(concaturl("addPostUserRel"), param);

const postAPI = {
  // 查询post list
  queryPostList: param => {
    return $http.post(`${window.RPConfig.mgt}/post/list/page`, param).then(response => response.data);
  },

  // 删除post
  deletePostById: param => {
    return $http.post(`${window.RPConfig.mgt}/post/removeByIds`, param).then(response => response.data);
  },

  queryPostAssignedRole: postId => {
    return $http.post(`${window.RPConfig.mgt}/post/getRoleByPostId?postId=${postId}`).then(response => response.data);
  },

  savePostAssignedRole: param => {
    return $http.post(`${window.RPConfig.mgt}/post/addPostRoleRel`, param).then(response => response.data);
  }
};
export default postAPI;
